#include <iostream>
#include <string>
#include "head.h"

using namespace std;

/* 类模板 */

template
< typename T1, typename T2 >
class Test
{
public:
    void add(T1 a, T2 b)
    {
        cout << "void add(T1 a, T2 b)" << endl;
        cout << a + b << endl;
    }

};

template
< typename T1, typename T2 >
class Test < T1*, T2* > //当 Test 类模板的两个参数为指针时，使用这个实现
{
public:
    void add(T1* a, T2* b)
    {
        cout << "void add(T1* a, T2* b)" << endl;
        cout << *a + *b << endl;
    }
};

/* 类模板的部分特化 */
template
< typename T >
class Test < T, T > //当 Test 类模板的两个参数完全相同的时，使用这个实现
{
public:
    void add(T a, T b)
    {
        cout << "void add(T a, T b)" << endl;
        cout << a + b << endl;
    }
    void print()
    {
        cout << "class Test < T, T >" << endl;
    }
};

/* 类模板的完全特化 */
template
< >
class Test < void* , void* >//当 Test 类模板的两个参数是 void* 类型时，使用这个实现
{
public:
    void add(void* a, void* b)
    {
        cout << "void add(void* a, void* b)" << endl;
        cout << "Error to add void* parma ..." << a << b << endl;
    }
};

int class_mode_test(void)
{
    Test<int, float> t1;
    Test<long, long> t2;
    Test<void*, void*> t3;

    t1.add(1, 2.5);

    t2.add(5, 5);
    t2.print();

    t3.add(NULL, NULL);

    Test<int*, double*> t4;
    int a = 3;
    double b = 4.5;
    t4.add(&a, &b);

    return 0;
}
